package com.msb;

/**
 * qccr.com Inc.
 * Copyright (c) 2018-2020 All Rights Reserved.
 */
public class _04对数器 {

    public static void main(String[] args) {
        int count  = 100000;
        for (int i = 0; i < count; i++) {
            int[] ints = randomArr(5, 500);
            _02简单排序.insertSort(ints);
            if (!checkSorted(ints)) {
                System.out.println("排序错误");
                break;
            }
        }
    }

    static int[] randomArr(int maxLen, int maxValue) {
        int len = (int) (Math.random() * maxLen);
        int[] arr = new int[len];
        for (int i = 0; i < len; i++) {
            arr[i] = (int) (Math.random() * maxValue);
        }
        return arr;
    }

    static boolean checkSorted(int[] arr) {
        if (arr.length < 2) {
            return true;
        }
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] < arr[i - 1]) {
                return false;
            }
        }
        return true;
    }
}
